package com.drakulo.games.ais.core.delayed;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

import com.drakulo.games.ais.core.Colony;
import com.drakulo.games.ais.core.Resource;

/**
 * This manager handles creation and cache of special actions
 * 
 * @author Drakulo
 * 
 */
public final class SpecialActionManager {
	private static Map<String, ColonyAction> actions = new HashMap<String, ColonyAction>();

	/** Initializes all special actions */
	public static void create(String name, int duration,
			Map<Resource, BigDecimal> costMap, String gfxKey, String i18nKey) {
		ColonyAction sa = new ColonyAction(null, name, costMap, duration, 0,
				gfxKey, i18nKey);
		actions.put(sa.getName(), sa);
	}

	public static Runnable createCallBackFor(String name, Colony c) {
		if ("robot_creation".equals(name)) {
			return init_robot_creation(c);
		} else if ("robot_creation_adv".equals(name)) {
			return init_robot_creation_adv(c);
		}
		return null;
		
		
	}

	public static ColonyAction get(Colony c, String name) {
		ColonyAction ca = actions.get(name).clone();
		ca.setCallback(createCallBackFor(name, c));
		ca.setColony(c);
		return ca;
	}

	private static Runnable init_robot_creation(final Colony c) {
		return new Runnable() {

			@Override
			public void run() {
				c.addRobot();
			}
		};
	}

	private static Runnable init_robot_creation_adv(final Colony c) {
		return new Runnable() {

			@Override
			public void run() {
				c.addRobot();
			}
		};
	}
}
